const jsonwebtoken = require("jsonwebtoken");
const { v4: uuidv4 } = require("uuid");
const { jwt } = require("../config");
const commonModels = require("../models/common");
/**
 * 生成token
 * @param {*} openid
 * @returns
 */
exports.generateToken = async (openid) => {
    // 生成userId
    const userId = uuidv4();

    // const expiresIn = "2h"; // Token 有效期
    // 生成JWT token
    const token = await jsonwebtoken.sign(
        {
            userId,
            openid
        },
        jwt.secret,

        { expiresIn: jwt.expiresIn }
    );
    return token;
};
exports.getStableAccessToken = async ({ access_token }) => {
    await commonModels.getStableAccessToken({ access_token });
};
